package net.tngou.tpage.action.api;

import java.io.IOException;
import java.util.Map;

import javax.servlet.ServletException;

import net.tngou.tpage.action.BaseAction;
import net.tngou.tpage.pojo.Access;
import net.tngou.tpage.pojo.Template;

/**
 * 访问
 * @author tngou@tngou.net
 *
 */
public class AccessApi extends BaseAction {

	@Override
	public void execute() throws ServletException, IOException {
		if(user==null){
			run_nologin();return;
		}
//		service.getPage(ask.getPage(), ask.getRows(), filter, Access.class)
	}
	
	/**
	 * 添加数据
	 */
	public void add() {
		if(user==null){
			run_nologin();return;
		}
		Access bean = getAsk(Access.class);
		if(bean.getTemplate()==0){
			run_false("请求的参数正确！");return;
		}
		Template template = bean.get(bean.getTemplate());
		if(template==null)
		{
			run_false("请求的数据不正确！");return;	
		}
		if(!((template.getUser()==0&&user.getRole()==0)||template.getUser()==user.getId())){
			run_false("没有修改权限！");return;	
		}		
		long id = bean.save();		
		if(id>0){
			
			Map<String, String[]> map = request.getParameterMap();
			
			
			run_success("添加成功！",id);
		}else {run_false("添加失败！");return;}
	}
}
